<?php

namespace App\Modules\User\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Class Visitor
 * @package App\Modules\User\Models
 * @property integer $user_id
 * @property integer $referrer_id
 */
class Visitor extends Model
{
    protected $fillable = [
        'user_id',
        'referrer_id'
    ];

    public function setReferrer(User $user, $referrerId)
    {
        self::query()
            ->create([
                'user_id' => $user->id,
                'referrer_id' => $referrerId,
            ]);
        $user->referrer_id = $referrerId;
        $user->save();
    }
}